    $(function() {
        loadCplbData(currentPage);
        /*日期*/
/*        jeDate("#lableDate", {
            format: "YYYY-MM-DD hh:mm:ss",
            isTime: false,
            minDate: "2014-09-19 00:00:00"
        })*/
    });

    //项目地址
    var ctx = "/knowledge/";
    //当前显示第几页
    var currentPage=1;
    //一共多少页数据
    var totalPage;

    //产品列表
    function loadCplbData(pageNum){
        var data = {
            currentPage : pageNum,
            pageSize : 8,
        };
        var url = ctx+'label/selectByPageLable';
        $.ajax({
            url : url,
            data : data,
            type : 'POST',
            dataType: "JSON",
            success : function(data) {
                if (data != null) {
                    var dataLists = data.fatherList;
                    var fatherList = dataLists.dataList;
                    var sonList = data.sonList;
                    var list = null;
                    var str="";
                    var intclass = 0;
                    if (fatherList != null) {
                        //当前第几页
                        currentPage=dataLists.currentPage;
                        //一共多少页数据
                        totalPage=dataLists.totalPage;
                        for(var i=0;i<fatherList.length;i++){
                            str+="<div class=\"main-content\">";
                            str+="<div class=\"main-content-icons\">";
                            str+="<i class=\"fa fa-plus-circle\" title=\"新增标签\" dataid=\""+fatherList[i].lableId+"\" lableName=\""+fatherList[i].lableName+"\"></i>";
                            str+="<i class=\"fa fa-times-circle\" title=\"删除标签\" dataid=\""+fatherList[i].lableId+"\"></i>";
                            str+="</div>";
                            str+="<div class=\"main-content-tree\">";
                            str+="<div class=\"main-content-tree-title\">";
                            str+="<i class=\"fa fa-minus\" id=\"icons"+i+"\">&nbsp;&nbsp;"+isLengs(fatherList[i].lableName)+"</i>";
                            str+="</div>";
                            str+="<div class=\"main-content-tree-content\" code=\"icons"+i+"\">";
                            //子标签获取........
                            list = returnSonArray(fatherList[i].lableId,sonList);
                            if(list.length>0){
                                intclass = list.length;
                            }else{
                                intclass = 1;
                            }
                            str+="<div class=\"main-content-tree-content-tag margin"+intclass+"\">";
                            for(var k=0;k<list.length;k++){
                                str+="<span class=\"text-clss\" dataid=\""+list[k].lableId+"\">"+list[k].lableName+"</span>&nbsp;<i class=\"fa fa-times\" dataid=\""+list[k].lableId+"\"></i><br/>";
                            }
                            str+="</div>";
                            str+="</div>";
                            str+="</div>";
                            str+="</div>";
                            list = null;
                        }
                        //构建分页信息
                        loadPage(dataLists);
                    }else{
                        $("#page").text("");
                        //str+="<div class=\"context_item\">";
                        //str+="<div class=\"notdata\">暂无数据</div>";
                        //str+="</div>";
                    }
                    $("#lable_list").html(str);
                }
            },
            error : function(error) {
                alert("获取标签列表失败。");
            }
        });
    }

    //构建分页信息
    function loadPage(data){
        $("#page").text("");
        var pageStr = "";
        var pageNum = 0;
        pageStr += "<div class=\"page-class\">";
        pageStr += "<div class=\"page-class-shangyiye\" id=\"prePage\">&lt;上一页</div>";
        var startindex = currentPage;  //当前页数
        var endindex = totalPage;  //总页数
        var spacenumb = endindex - startindex;
        if (spacenumb > 5) {
            endindex = startindex + 4;
        } else {
            if (totalPage > 5) {
                startindex = totalPage - 4;
            } else {
                startindex = 1;
            }
        }
        for (var i = startindex; i <= endindex; i++) {
            if (currentPage === i) {  //active默认选中样式
                pageStr += "<div class=\"page-class-dangqianye pageactive\" onclick=\"pageNum('" + i + "')\">" + i + "</div>"
            } else {
                pageStr += "<div class=\"page-class-dangqianye\" onclick=\"pageNum('" + i + "')\">" + i + "</div>"
            }
        }
        pageStr += "<div class=\"page-class-xiayiye\" id=\"nextPage\">下一页&gt;</div>";
        pageStr += "</div>";
        //pageStr += "合计"+data.totalPage+" 页";
        //pageStr += "共 "+data.totalRecord+"  条记录";
        $("#page").append(pageStr);
    }

    //上一页
    $(document).on("click","#prePage",function(){
        priviousPage();
    });

    //下一页
    $(document).on("click","#nextPage",function(){
        nextPage();
    });

    //下一页
    function nextPage(){
        if(currentPage==totalPage){
            alert("已经是最后一页数据!");
            return false;
        }else{
            loadCplbData(currentPage+1);
            return true;
        }
    };

    //当前页数加载
    function pageNum(pageNum){
            loadCplbData(pageNum);
    }

    //上一页
    function priviousPage(){
        if(currentPage==1){
            alert("已经是第一页数据!");
            return false;
        }else{
            loadCplbData(currentPage-1);
            return true;
        }
    }


    //判断为数据库null
    function isNull(reason){
        if(reason!=null&&reason!=""&&reason!="null"){
            return reason;
        }else{
            return "无";
        }
    }

    //+ 显示按钮
    $(document).on("click",".fa-plus-show",function(){
        $(this).attr("class","fa fa-minus");
        var id =  $(this).attr("id");
        $(".main-content-tree-content[code="+id+"]").show();  //取消上次选中样式
    });

    //-  隐藏按钮
    $(document).on("click",".fa-minus",function(){
        $(this).attr("class","fa fa-plus fa-plus-show");
        var id =  $(this).attr("id");
        $(".main-content-tree-content[code="+id+"]").hide();  //取消上次选中样式
    });


    //返回父标签的list集合
    function returnFatherList(lsit){
        var fatherList = new Array();
        for(var i=0;i<lsit.length;i++){
            if(lsit[i].lablePreid==null){
                fatherList.push(lsit[i]);
            }
        }
        return fatherList;
    }

    //返回子标签的list集合
    function returnSonList(lsit){
        var sonList = new Array();
        for(var i=0;i<lsit.length;i++){
            if(lsit[i].lablePreid!=null){
                sonList.push(lsit[i]);
            }
        }
        return sonList;
    }

    //根据父标签的id获取子标签的集合并且返回
    function returnSonArray(fid,sonList){
        var list = new Array();
        for(var i=0;i<sonList.length;i++){
            if(sonList[i].lablePreid==fid){
                list.push(sonList[i]);
            }
        }
        return list;
    }

    //字体长度判断
    function isLengs(str){
        if(str.length>6){
            str = str.substring(0,6)+"..."
        }
        return str;
    }

    //根据id删除子标签
    $(document).on("click",".fa-times",function(){
        var id =  $(this).attr("dataid");
        var msg = "确定删除标签？";
        confirm(msg, function() {
            $.get(ctx+"label/deleteLableId?id="+id, function(r) {
                if (r == 1) {
                    alert('删除成功。')
                    loadCplbData(currentPage);  //删除成功刷新列表
                }else{
                    alert('删除失败。')
                }
            });
        });
    });


    //根据id删除全部标签
    $(document).on("click",".fa-times-circle",function(){
        var id =  $(this).attr("dataid");
        var msg = "确定删除全部标签？";
        confirm(msg, function() {
            $.get(ctx+"label/deleteLablePreId?id="+id, function(r) {
                if (r == 1) {
                    alert('删除成功。')
                    loadCplbData(currentPage);  //删除成功刷新列表
                }else{
                    alert('删除失败。')
                }
            });
        });
    });

    //根据id修改子标签
    $(document).on("click",".text-clss",function(){
        var id =  $(this).attr("dataid");
        $.get(ctx+"label/getLableId?id="+id, function(r) {
            if (r != null) {
                $(".main").hide();
                $("#lableId").val(r.record.lableId);
                $("#lableName").val(r.record.lableName);
                $("#lablePreName").val(r.record.lablePreName);
                $("#lablePreid").val(r.record.lablePreid);
                $("#lableDesc").val(r.record.lableDesc);
                //$("#lableDate").val(r.record.lableDate);
                $("#lableSort").val(r.record.lableSort);
                $("#updateInset").show();
            }
        });
    });

    //确定修改
    $(document).on("click","#determine",function(){
        var id =  $("#lableId").val();
        var lableName = $("#lableName").val();
        var lableDesc = $("#lableDesc").val();
        var lablePreid = $("#lablePreid").val();
        //var lableDate = $("#lableDate").val();
        var lableSort = $("#lableSort").val();
        if (isBlank(lableName)) {
            alert("标签名称不能为空");
            return true;
        }
        if (isBlank(lableDesc)) {
            alert("描叙不能为空");
            return true;
        }
/*        if (isBlank(lableDate)) {
            alert("创建时间不能为空");
            return true;
        }*/
        if (isBlank(lableSort)) {
            alert("排序不能为空");
            return true;
        }
        var msg = "确定提交吗？";
        var data = {
            lableName : lableName,
            lableDesc : lableDesc,
            lablePreid:lablePreid,
            /*lableDate:  lableDate,*/
            lableSort:  lableSort,
            lableId : id
        }
        confirm(msg, function() {
            $.ajax({
                url: ctx + "label/knowLableUpdateAndInsertNew",
                data: data,
                type: 'POST',
                dataType: "JSON",
                success: function (data) {
                    if (data.code==200) {
                        alert("操作成功!");
                        $("#updateInset").hide();
                        $(".main").show();
                        loadCplbData(currentPage);  //删除成功刷新列表
                    }else{
                        alert(result.msg);
                    }
                }
            });
        });
    });

    //返回
    $(document).on("click","#return",function(){
        $(".main").show();
        $("#updateInset").hide();
    });

    //新增子标签
    $(document).on("click",".fa-plus-circle",function(){
        var id =  $(this).attr("dataid");
        var lableName =  $(this).attr("lableName");
        $(".main").hide();
        $("#lableId").val(null);
        $("#lableName").val("");
        $("#lablePreName").val(lableName);
        $("#lablePreid").val(id);
        $("#lableDesc").val("");
        //$("#lableDate").val("");
        $("#lableSort").val("");
        $("#updateInset").show();
    });


    //新增父标签
    $(document).on("click",".fa-plus-add",function(){
        $(".main").hide();
        $("#lableId").val(null);
        $("#lableName").val("");
        $("#lablePreName").val("");
        $("#lablePreid").val("");
        $("#lableDesc").val("");
        //$("#lableDate").val("");
        $("#lableSort").val("");
        $("#updateInset").show();
    });
